home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13428 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  8.4 KB

  1. Path: seagoon.newcastle.edu.au!usenet
  2. From: mazz@faceng.newcastle.edu.au (Richard Mazzaferri)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ vs Delphi 2.0
  5. Date: Tue, 26 Mar 1996 04:12:37 GMT
  6. Organization: Newcastle University
  7. Message-ID: <31576076.7093766@news.newcastle.edu.au>
  8. References: <825673272.2083@axiombc.demon.co.uk> <4hmop6$snh@cdshub.cdc.com> <4ims71$oh3@hawk.pix.za> <3152304b.5915048@news.newcastle.edu.au> <4j2u9o$s0n@nntp.interaccess.com>
  9. NNTP-Posting-Host: tesla.newcastle.edu.au
  10.  
  11. "Thaddeus L. Olczyk" <Polczyk@interaccess.com> wrote:
  12.  
  13. > mazz@faceng.newcastle.edu.au (Richard Mazzaferri) wrote:
  14.  
  15. > More importantly you can only pass functions and variables to a dll.
  16. > The class structure of your code will be completely lost.
  17.  
  18. Absolutely - this was meant to be implicit in my statement that you have to
  19. use a "straight C interface" - you can't pass C++ classes across the
  20. boundary.
  21.  
  22. > I have argued in the past and continue to argue now that it is a misnomer
  23. > to call Delphi OO. It partial emulates the C++/Eiffel model of static 
  24. > typing, but misses severely by what it keeps out. It partially emulates
  25. > the Smalltalk model of dynamic typing, but in a convoluted way.
  26.  
  27. Could you expound on this - perhaps in e-mail if you've done this before
  28. publicly?  I'm intellectually interested in the important differences you
  29. see between the models.  The debate about what does and what doesn't
  30. constitute "true OO" tends to take on religious overtones very quickly, so
  31. I'm not going to waste time discussing *that* particular point.  On the
  32. other hand, I have to state that the commercial realities are (IMHO) that
  33. Delphi is the best choice for many applications (despite any real or
  34. perceived intellectual shortcomings) so your discussion is unlikely to
  35. change my viewpoint there :-)
  36.  
  37. > >The biggest omissions are multiple inheritance (which can generally be
  38. > >faked with a bit of work) and templates (no workaround :-(.  Some of the
  39.  
  40. > Many times a lot of work or virtually impossible. 
  41.  
  42. Most of the time, multiple inheritance is not *strictly* necessary
  43. (although I have one case where it is), and the workaround via delegation
  44. takes a bit of time - you have to declare functions that would otherwise be
  45. inherited, and in their implementation call the delegated object instead.
  46. While this is some work that could be avoided by implementing multiple
  47. inheritance, it is not virtually impossible - it just leads to a different
  48. sort of class hierarchy design.  I would prefer to have real multiple
  49. inheritance, but in the real world projects I've done so far, it hasn't
  50. been sorely missed.  Now, what I *really* miss is templates.
  51.  
  52. > >big wins are properties and really good exception handling and RTTI.  I
  53. > >also find that I generate far fewer bugs in Delphi than I did in C++,
  54. > >probably to do with the type checking.
  55.  
  56. > Or more to do with the fact that you probably wrote C code in C++.
  57.  
  58. I resent that :-)  
  59.  
  60. I did *not* and do not write C code in C++ - ask me for sample code or
  61. references :-)  I recently added features to a public domain utility
  62. program written in straight C, and I found it a very restrictive exercise.
  63.  
  64. > Properties -- A feature of any dll/vbx type architecture. Affects most 
  65. > programming very little ( at the cost of some overhead too ).
  66.  
  67. Perhaps it is - but I believe that most DLL/VBX properties are implemented
  68. as a set of longint/pointer values keyed on a longint property identifier,
  69. whereas Delphi's properties are typed class members just like data or
  70. function members.  They are inherited, and can be public/private/protected
  71. or published, and effectively hide the implementation.  
  72.     The use of object member function pointers (generally as properties) is
  73. much more useful than those in C++ (paradoxically) because C++'s member
  74. function pointers are strongly typed.  This makes the use of member
  75. function pointers in C++ as event handlers for GUI functions a lot more
  76. difficult, because you can only point to a member function of an object of
  77. the class declaring the function.
  78.  
  79. > Exception handling -- a feature of both Delphi and C++ and is used the 
  80. > same way in both. Except for one exception, Delphi's model of 
  81. > explicitly constructing and destructing objects means that a lot more 
  82. > effort is expended to make sure resources are freed ( nested finally 
  83. > blocks) .
  84.  
  85. Internal to a class, the resource freeing problem is identical to that in
  86. C++ - generally, any member you allocate in the class (typically in the
  87. constructor), you free in the class (typically in the destructor).  Given
  88. that *most* to *all* of the code in a Delphi program is inside a class,
  89. this gives no extra work.  Where the "try ... finally" resource protection
  90. is required is for what would be automatic variables in C++, and there is
  91. generally no need for *nested* "try ... finally" blocks.  Consider:
  92.  
  93. procedure TSomeClass.SomeFn;
  94. var
  95.     o1 : TObject1;
  96.     o2 : TObject2;
  97. begin
  98.     try
  99.         { Both o1 and o2 are nil at this point. }
  100.         o1 := TObject1.Create;
  101.         o2 := TObject2.Create;
  102.         { Do something with o1/o2 }
  103.     finally
  104.         { Freeing a nil object has no effect. }
  105.         o2.Free;
  106.         o1.Free;
  107.     end;
  108. end;
  109.  
  110. I can type a try ... finally block in very little time, so I don't consider
  111. this "a lot more effort", but YMMV.  Many people would consider that the
  112. explicit construction/destruction is clearer than the implicit model in
  113. C++, but I don't really care either way.
  114.  
  115. > As for RTTI, it is similar to C++ RTTI , but I believe the 
  116. > standards committee considers it a nessecsary evil, because programmers 
  117. > can do it themselves quite easily. It is a bad practice
  118. > because it hurts strong type checking. Unfortunately in Delphi 
  119. > you have to revert to it often because of the poor object model.
  120.  
  121. I find that there are three main reasons to revert to RTTI.  
  122.  
  123. The first is the lack of templates, leading to generic container classes
  124. (as if they are parameterised on TObject rather than the class of choice).
  125.  
  126.  
  127. The second is the way the Windows GUI works: messages are sent to and from
  128. all sorts of GUI "objects" (and even that rarely requires RTTI).  This is
  129. reflected in the VCL design where GUI event handlers are by default a
  130. member function of the form - something that is difficult to accomplish in
  131. C++, because it tends to require that the form class declare a virtual
  132. event handler function for *every* type of event that it wants to handle.  
  133.  
  134. The third use of RTTI I find is for heterogeneous collections.
  135. Traditionally in C++ this would be handled by factoring out some sort of
  136. base class with appropriate virtual functions and parameterising the
  137. collection class on this base class.  There are situations where this is
  138. either not appropriate, or requires RTTI anyway, no matter which language
  139. you choose.
  140.  
  141. Now, apart from these reasons, I haven't had occasion to use RTTI.  Do any
  142. of these reasons stem from the "poor object model"?  If not, could you give
  143. me some examples that do so that I understand what you are referring to?
  144.  
  145. > I would say that Delphi is a tool usefull for single programmers, or
  146. > for a small team working on a small (less then three month long ) project.
  147.  
  148. Hmm, small team, four months and counting... YMMV.
  149.  
  150. As a commercial choice, I find that for my current projects, Delphi is
  151. superior to C++.  I can produce a lot more personally (and I'm no slouch in
  152. C++), AND I can bring new programmers into the team and have them producing
  153. *good* code a lot more quickly in Delphi than with C++.  It seems to be a
  154. lot easier to produce bad code in C++, and consequently a lot harder to
  155. find good software engineers.  Again, YMMV.
  156.  
  157. This is not to say that there are language features that are better
  158. implemented (or implemented at all :-) in C++ (or Eiffel, or Smalltalk...).
  159. However, the bottom line is either the purity of the intellectual OO model,
  160. or sustained earning power.  A different bottom line will lead to different
  161. conclusion.
  162.  
  163. > >I don't understand why it "..discourages one from using code...". 
  164.  
  165. > One of the major selling points of Delphi I hear from most Delphi
  166. > programmers is "isn't it great I can write this application with
  167. > virtually no code".
  168.  
  169. I think you'll find that constructing most of the GUI - including a
  170. significant amount of database manipulation - can be accomplished with very
  171. little code, which leads programmers to make these statements.  This does
  172. not suggest to me that Delphi discourages the use of code.  In practice,
  173. the guts of most real applications requires decent amounts of code.
  174.  
  175. Have fun,
  176.     Mazz.
  177.  
  178. PS Looking at the subject line: I haven't seen Delphi v2.0 yet :-)
  179. mazz@faceng.newcastle.edu.au
  180.